package com.centronix.manager.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.centronix.bean.ComboBean;
import com.centronix.dao.ProductCatagoryDAO;
import com.centronix.domain.ProductCatagory;
import com.centronix.manager.ProductCatManager;
@Service(value="productCatManager")
@Transactional
public class ProductCatManagerImpl implements ProductCatManager , Serializable{
	
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private ProductCatagoryDAO productCatagoryDAO;
	
	public List<ProductCatagory> findAllProdCat(){
		return productCatagoryDAO.findAll();
	}
	
	public Boolean saveProdCat(ProductCatagory productCatagory){
		productCatagoryDAO.saveAndFlush(productCatagory);
		return true;
	}
	
	public Boolean deleteProdCat(int catagoryId){
		productCatagoryDAO.delete(catagoryId);
		return true;
	}
	
	public List<ComboBean> getProductCatCombo(){
		List<ComboBean> comboBeans = new ArrayList<>();
		comboBeans.add(ComboBean.getDefaultCombo());
		List<ProductCatagory> productCatagories= productCatagoryDAO.findAll();
		ComboBean comboBean = null;
		for (ProductCatagory productCatagory : productCatagories) {
			comboBean = new ComboBean();
			copyProductCatagoryToComboBean(productCatagory, comboBean);
			comboBeans.add(comboBean);
		}
		return comboBeans;
	}
	
	public void copyProductCatagoryToComboBean(final ProductCatagory productCatagory, final ComboBean comboBean) {
		comboBean.setValue(String.valueOf(productCatagory.getCatagoryId()));
		comboBean.setLabel(productCatagory.getNarrative());
	}

	public ProductCatagoryDAO getProductCatagoryDAO() {
		return productCatagoryDAO;
	}

	public void setProductCatagoryDAO(ProductCatagoryDAO productCatagoryDAO) {
		this.productCatagoryDAO = productCatagoryDAO;
	}
	
	
	
}
